# 安装基础环境
sudo apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
# 执行配置k8s阿里云源  
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
# 执行更新
sudo apt-get update -y
# 安装kubeadm、kubectl、kubelet  
sudo apt-get install -y kubelet=1.23.1-00 kubeadm=1.23.1-00 kubectl=1.23.1-00
# 阻止自动更新(apt upgrade时忽略)。所以更新的时候先unhold，更新完再hold。
sudo apt-mark hold kubelet kubeadm kubectl

# 关闭swap
sudo swapoff -a
# 关闭防火墙
sudo ufw disable

echo 'y' | sudo kubeadm reset

# 删除相关进程
process=$(ps -aux | grep 'kube' | grep -v grep | awk '{print $2}')
for id in $process
do
    sudo kill $id
done
# 删除相关配置文件和证书
sudo rm -f /etc/kubernetes/*.conf /etc/kubernetes/pki/ca.crt
sudo rm /etc/cni/net.d/* -f
